package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import learn.sss;
import proxy.Proxyer.Hello;
import proxy.Proxyer.IHello;

public class ProxyHandler implements InvocationHandler {
	static proxy.Proxyer.Hello hello = new Proxyer.Hello();
	String ss = "";

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		System.out.println("before method operate...");
		method.invoke(hello, args);
		System.out.println("...after method oprate");
		return null;
	}

	public static void main(String[] args) {
		IHello helloEn = (IHello) Proxy.newProxyInstance(hello.getClass().getClassLoader(),
				hello.getClass().getInterfaces(), new ProxyHandler());
		// try {
		// helloEn.sayHello1();
		// } catch (InterruptedException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		//
		// IHello hello2 = (IHello)
		// Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
		// Hello.class.getInterfaces(), new InvocationHandler() {
		//
		// @Override
		// public Object invoke(Object proxy, Method method, Object[] args)
		// throws Throwable {
		// System.out.println("before operate...");
		// method.invoke(helloEn, args);
		// System.out.println("after oprate....");
		// return null;
		// }
		// });
		// try {
		// hello2.sayHello1();
		// } catch (InterruptedException e) {
		// // TODO Auto-generated catch block
		// e.printStackTrace();
		// }
		ProxyHandler proxyHandler = new ProxyHandler();
//		proxyHandler.finalTest("ff");
//		proxyHandler.testin();
		testin();
	}

	static String gf = "fd";

	public void finalTest(String s) {
		TestInterface testInterface = new TestInterface() {

			@Override
			public void test(String ss) {
				// TODO Auto-generated method stub
				System.out.println(s);
				System.out.println(gf);
				System.out.println(ss);
			}
		};
		testInterface.test("hf");
	}

	public static void testin() {
		int key = 8;
		final class innn {
			public void tests() {
				System.out.println(key);
				System.out.println(gf);
			}
		}
		new innn().tests();
	}

	public class in {
		int i = 9;

		public void inn(String ss) {
			System.out.println(gf);
		}
	}
}
